/*
 * GameObject.cpp
 *
 *  Created on: 17/05/2013
 *      Author: vitor
 */

#include "GameObject.h"

GameObject::GameObject(float x, float y, float w, float h) {
	box.setPosition(Point(x, y));
	box.setW(w);
	box.setH(h);
}

GameObject::GameObject(Point position, float w, float h) {
	box.setPosition(position);
	box.setW(w);
	box.setH(h);
}

GameObject::~GameObject() {
}

bool GameObject::valueInRange(float value, float min, float max) {
	return (value >= min) && (value <= max);
}

bool GameObject::collidesWith(GameObject* other) {

	float diffX = (box.getPositionRef()->getX() - box.getW() / 2)
			- (other->getBox()->getPositionRef()->getX()
					- other->getBox()->getW() / 2);
	float diffY = (box.getPositionRef()->getY() - box.getH() / 2)
			- (other->getBox()->getPositionRef()->getY()
					- other->getBox()->getH() / 2);

	if (diffX > other->getBox()->getW() || -diffX > box.getW()) {
		return false;
	}
	if (diffY > other->getBox()->getH() || -diffY > box.getH()) {
		return false;
	}

	return true;

}
